﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace The_Last_Knights.Helper.Xml
{
    public class ConditionReader: ReaderEntity
    {
        public override object Read(XElement element, string ID, int level)
        {
            List<string>[]condition = new List<string>[3];
            for (var i = 0; i < 3; i++)
            {
                condition[i] = new List<string>();
            }

            var defs = element.Descendants(XName.Get(@"Element"));
            foreach (var xElement in defs)
            {
                string type = xElement.Attribute(XName.Get(@"Type")).Value;
                int lev = int.Parse(xElement.Attribute(XName.Get(@"Level")).Value);
                if (lev == level + 1)
                {
                    string data = (string) Factory.Read(xElement, null, "Single", lev);
                    if (data != null && data != "")                        
                    switch (type)
                    {
                        case "Finish":
                            condition[0].Add(data);
                            break;
                        case "Running":
                            condition[1].Add(data);
                            break;
                        case "NotRun":
                            condition[2].Add(data);
                            break;
                    }            
                }                       
            }
            return condition;
        }
    }
}
